package com.gree.flowable.app.tools.utils;

import org.flowable.editor.language.json.converter.util.CollectionUtils;

import java.util.List;
import java.util.Map;

public class StringSplitUtil {
    public static String getInTwoChar(String params, char a, char b) {
        String result = null;
        int i = params.indexOf(a);
        int j = params.indexOf(b);
        if (i != -1 && j != -1) {
            result = params.substring(i + 1, j);
        }
        return result;
    }

    public static String[] createApprovers2(List<Map> map) {
        if (CollectionUtils.isNotEmpty(map)) {
            StringBuffer approverstr = new StringBuffer();
            StringBuffer finalApproverstr = approverstr;

            StringBuffer nodestr = new StringBuffer();
            StringBuffer finalNodestr = nodestr;
            map.forEach(user -> {
                finalApproverstr.append(user.get("user").toString()).append(";");
                finalNodestr.append(user.get("nodeName").toString()).append(";");
            });
            if (approverstr.length() > 0) {
                approverstr = approverstr.deleteCharAt(approverstr.length() - 1);
                nodestr = nodestr.deleteCharAt(nodestr.length() - 1);
            }
            String[] result = new String[]{approverstr.toString(), nodestr.toString()};
            return result;
        }
        return null;
    }
}
